using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using SpriteClasses;

namespace FrostFights
{

    public class Player : SpriteFromSheet2
    {
        protected Vector2 acceleration;
        public int knockBackValue = 1;
        public float Health;
        public float MaxHealth;
        public Vector2 Acceleration { get { return acceleration; } set { acceleration = value; } }
        public float aimRotation;
        public float TotalTime = 0.0f;
        public float nextSnowballLevel = 2.0f;
        public int playerNumber;
        public GraphicsDeviceManager graphics;
        public PlayerIndex controllerIndex;
        public Boolean isRunning = false;
        public Boolean isIdle = true;
        private Boolean isCrouching = false;
        private Boolean canMove = true;
        private Boolean canShoot = true;
        private Boolean jumping = false;
        private Boolean RT_Pressed = false;
        private Boolean RT_Held = false;
        private Texture2D aimImage;
        protected List<Projectile> projectiles = new List<Projectile>();
        public float jumpPower = -85f;
        float timeInterval = 0f;
        public Vector2 aimPositionDefault; //the arm's target position relative to the player
        public Vector2 aimPosition; // the arm's current realtime position
        private Vector2 aimOrigin;
        private Vector2 projectilePosition; // the projectile's position
        private GamePadState newGamePad;
        private GamePadState previousState;
        private KeyboardState newKeyState;
        private KeyboardState previousKeyState;
        public int direction = 0; // 1 is going right, -1 is going left, 0 is no direction, stationary.
        int weaponToggle = 0; // Used right within shooting controls
        private const int WEAPONAMOUNT = 4; // Number of weapons the players can cycle through.
        private const float MAX_AMMO_AMOUNT = 70f;
        public float ammoAmount = MAX_AMMO_AMOUNT;
        //Animation variables
        static private Vector2 idleStart = new Vector2(0, 0);
        static private Vector2 idleEnd = new Vector2(3, 0);
        static private Vector2 crouchStart = new Vector2(0, 1);
        static private Vector2 crouchLoopStart = new Vector2(9, 1);
        static private Vector2 crouchEnd = new Vector2(15, 1);
        /* MIGHT NEED THESE ANIMATIONS
            static private Vector2 dieStart = new Vector2(0, 2);
            static private Vector2 dieEnd = new Vector2(7, 2);
        */
        /* CURRENTLY NOT NEEDED
            static private Vector2 runningStart = new Vector2(4, 0);
            static private Vector2 runningEnd = new Vector2(3, 1);
            static private Vector2 idleStart = new Vector2(0, 0);
            static private Vector2 idleEnd = new Vector2(3, 0);
            static private Vector2 throwStart = new Vector2(4, 1);
            static private Vector2 throwEnd = new Vector2(7, 1);
            static private Vector2 jumpStart = new Vector2(1, 5);
            static private Vector2 jumpEnd = new Vector2(7, 5);
        */

        public Player(Texture2D image, Texture2D arm, int playerNumber, PlayerIndex controllerIndex, ContentManager content, GraphicsDeviceManager graphics)
            : base(image,new Vector2(400 * playerNumber - 150,0), new Vector2(0, 200), 0f, 1f, SpriteEffects.None, 5,
            new Vector2(44, 86), idleStart, idleEnd, new Vector2(15, 2), 0.1f)
        {
            this.graphics = graphics;
            this.playerNumber = playerNumber;
            aimRotation = 0;
            aimImage = arm;
            aimOrigin = new Vector2(0, aimImage.Height / 2);
            MaxHealth = 200;
            Health = MaxHealth;
            this.controllerIndex = controllerIndex;
            spriteOrigin.Y = 0;
        }

        public void Update(GameTime gameTime, GraphicsDevice Device, Map map)
        {
            Update(gameTime, Device);
            newGamePad = GamePad.GetState(controllerIndex, GamePadDeadZone.None);
            newKeyState = Keyboard.GetState();
            previousKeyState = Keyboard.GetState();

            //Check for death:
            if (Health <= 0 || IsOffScreen(Device))
            {
                Respawn(Device);
            }

            //Updating projectiles if they are present
            //-----------------------------------------
            if (projectiles.Count > 0)
            {
                for (int i = 0; i < projectiles.Count; i++)
                {
                    if (projectiles[i].Active)
                    {
                        projectiles[i].Update(gameTime, Device);
                        if (projectiles[i] is Grenade)
                        {
                            if (!((Grenade)(projectiles[i])).upgraded && ((Grenade)(projectiles[i])).timer <= 0)
                            {
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, -1.5f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, -1f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, -0.5f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 0.0f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 0.5f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 1f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 1.5f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 2f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 4f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 3.5f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 3f));
                                projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 2.5f));
                                projectiles[i].Active = false;
                            }
                            else if (((Grenade)(projectiles[i])).upgraded)
                            {
                                foreach (CollisionTiles tile in map.CollisionTiles)
                                {
                                    if (projectiles[i].CollisionRectangle.Intersects(tile.Rectangle))
                                    {
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, -1.5f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, -1f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, -0.5f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 0.0f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 0.5f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 1f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 1.5f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 2f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 4f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 3.5f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 3f));
                                        projectiles.Add(new Snowball(projectiles[i].Position, Vector2.Zero, 2.5f));
                                        projectiles[i].Active = false;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        projectiles.RemoveAt(i);
                    }

                }
            }

            //Update aimPosition
            aimPositionDefault = new Vector2(position.X - FrameSize.X / 2, position.Y + 27);

            // DIRECTIONAL AIM ADJUSTING --------------------------------------
            if (direction == 1)
            {
                aimPosition = new Vector2(position.X - FrameSize.X / 2 + 5, aimPositionDefault.Y);
                aimOrigin.X = 0;
                aimRotation = (float)Math.Atan2(newGamePad.ThumbSticks.Right.X, newGamePad.ThumbSticks.Right.Y) - (float)(Math.PI / 2);
                aimRotation = MathHelper.Clamp(aimRotation, -1.5f, 1.5f); // make sure the rotation angle is within this range
                projectilePosition = aimPosition + new Vector2((float)Math.Cos(aimRotation), (float)Math.Sin(aimRotation)) * aimImage.Height * 3;
            }
            else if (direction == -1)
            {
                aimPosition = new Vector2(position.X + FrameSize.X / 2 - 5, aimPositionDefault.Y);
                aimOrigin.X = aimImage.Width;
                aimRotation = (float)Math.Atan2(newGamePad.ThumbSticks.Right.X, newGamePad.ThumbSticks.Right.Y) + (float)(Math.PI / 2);
                aimRotation = MathHelper.Clamp(aimRotation, -1.5f, 1.5f); // make sure the rotation angle is within this range
                projectilePosition = aimPosition - new Vector2((float)Math.Cos(aimRotation), (float)Math.Sin(aimRotation)) * aimImage.Height * 3;
            }

            //updates projectiles then after checks if player is jumping
            //if player is jumping they can't move or fire snowballs
            if (jumping)
            {
                //allows the player to change direction in the air
                if (GamePad.GetState(controllerIndex).ThumbSticks.Left.X > 0.5)
                {
                    if (direction != 1)
                    {
                        SpriteEffect = SpriteEffects.None;
                        direction = 1;
                    }
                    originalVelocity.X = 30f;
                }
                else if (GamePad.GetState(controllerIndex).ThumbSticks.Left.X < -0.5)
                {
                    if (direction != -1)
                    {
                        SpriteEffect = SpriteEffects.FlipHorizontally;
                        direction = -1;
                    }
                    originalVelocity.X = -30f;
                }
                else
                {
                    acceleration.X = 0f;
                }
                timeInterval = 0.1f;//(float)gameTime.ElapsedGameTime.TotalSeconds;
                Velocity = OriginalVelocity + Acceleration * timeInterval;
                Position += OriginalVelocity * timeInterval + 0.5f * Acceleration * (timeInterval * timeInterval);
                OriginalVelocity = Velocity;
            }
                // MOVEMENT CONTROLS -----------------------------------------------
                if (canMove)
                {
                    if (GamePad.GetState(controllerIndex).ThumbSticks.Left.X > 0)
                    {

                        if (direction != 1) // check in order to flip the sprite accordingly
                        {
                            SpriteEffect = SpriteEffects.None;
                            direction = 1;
                        }
                        /*   CURRENTLY NOT NEEDED
                        if (EndFrame == idleEnd)
                        {
                            isRunning = true;
                            changeFrameStartAndEnd(runningStart, runningEnd);
                        }*/
                        isIdle = false;
                        Right(gameTime);
                    }
                    else if (GamePad.GetState(controllerIndex).ThumbSticks.Left.X < 0)
                    {
                        if (direction != -1)
                        {
                            SpriteEffect = SpriteEffects.FlipHorizontally;
                            direction = -1;
                        }
                        /*  CURRENTLY NOT NEEDED
                        if (EndFrame == idleEnd)
                        {
                            isRunning = true;
                            changeFrameStartAndEnd(runningStart, runningEnd);
                        }*/
                        isIdle = false;
                        Left(gameTime);
                    }
                }
                if (GamePad.GetState(controllerIndex).ThumbSticks.Left.X == 0)
                {
                    /*   CURRENTLY NOT NEEDED
                   if (EndFrame == runningEnd)
                   {
                       isRunning = false;
                       changeFrameStartAndEnd(idleStart, idleEnd);
                   }*/
                   isIdle = true;
                   Idle();
                }

                // SHOOTING CONTROLS -------------------------------
                // weapon toggling, simple way for a player to hold as many weapons as we want, and scroll through them easily
                if (GamePad.GetState(controllerIndex).Buttons.RightShoulder == ButtonState.Pressed && previousState.Buttons.RightShoulder == ButtonState.Released)
                {
                    weaponToggle += 1;
                    if (weaponToggle > WEAPONAMOUNT-1)
                        weaponToggle = 0;
                }
                else if (GamePad.GetState(controllerIndex).Buttons.LeftShoulder == ButtonState.Pressed && previousState.Buttons.LeftShoulder == ButtonState.Released)
                {
                    weaponToggle -= 1;
                    if (weaponToggle < 0)
                        weaponToggle = WEAPONAMOUNT - 1;
                }

                if (canShoot)
                {
                    if (GamePad.GetState(controllerIndex).Triggers.Right > 0.5f)
                    {
                        TotalTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                        RT_Pressed = true;
                        if (TotalTime > nextSnowballLevel)  //Check if it's been held long enough for level up
                        {
                            RT_Pressed = false;
                            RT_Held = true;
                            TotalTime = 0.0f;
                        }
                    }
                    if (GamePad.GetState(controllerIndex).Triggers.Right == 0.0f && RT_Pressed && !RT_Held) //Throws a projectile
                    {
                        //playOnce(throwStart, throwEnd);   // CURRENTLY NOT NEEDED
                        if (direction == 1)
                        {
                            switch (weaponToggle)
                            {
                                case 0:
                                    if (ammoAmount >= 2)
                                    {
                                        ammoAmount -= 2;
                                        projectiles.Add(new Snowball(projectilePosition, Vector2.Zero, aimRotation));
                                    }
                                    break;
                                case 1:
                                    if (ammoAmount >= 12)
                                    {
                                        ammoAmount -= 12;
                                        projectiles.Add(new Grenade(projectilePosition, Vector2.Zero, aimRotation, false));
                                    }
                                    break;
                                case 2:
                                    if (ammoAmount >= 8)
                                    {
                                        ammoAmount -= 8;
                                        for (int i = 0; i <= 200; i += 50)
                                            projectiles.Add(new Icicle(new Vector2(position.X + (100 + i), 0 - i)));
                                    }
                                    break;
                                case 3:
                                    if (ammoAmount >= 4)
                                    {
                                        ammoAmount -= 4;
                                        projectiles.Add(new Iceball(projectilePosition, Vector2.Zero, aimRotation));
                                    }
                                    break;
                            }
                        }
                        else if (direction == -1)
                        {
                            switch (weaponToggle)
                            {
                                case 0:
                                    if (ammoAmount >= 2)
                                    {
                                        ammoAmount -= 2;
                                        projectiles.Add(new Snowball(projectilePosition, Vector2.Zero, aimRotation + (float)Math.PI));
                                    }
                                    break;
                                case 1:
                                    if (ammoAmount >= 12)
                                    {
                                        ammoAmount -= 12;
                                        projectiles.Add(new Grenade(projectilePosition, Vector2.Zero, aimRotation + (float)Math.PI, false));
                                    }
                                    break;
                                case 2:
                                    if (ammoAmount >= 8)
                                    {
                                        ammoAmount -= 8;
                                        for (int i = 0; i <= 200; i += 50)
                                            projectiles.Add(new Icicle(new Vector2(position.X - (100 + i), 0 - i)));
                                    }
                                    break;
                                case 3:
                                    if (ammoAmount >= 4)
                                    {
                                        ammoAmount -= 4;
                                        projectiles.Add(new Iceball(projectilePosition, Vector2.Zero, aimRotation + (float)Math.PI));
                                    }
                                    break;
                            }
                        }
                        TotalTime = 0.0f;   //Resetting the values
                        RT_Pressed = false;
                    }
                    else if (GamePad.GetState(controllerIndex).Triggers.Right == 0.0f && RT_Held) //Throws a snowburst
                    {
                        //playOnce(throwStart, throwEnd);   // CURRENTLY NOT NEEDED
                        if (direction == 1)
                        {
                            switch (weaponToggle)
                            {
                                case 0:
                                    if (ammoAmount >= 6)
                                    {
                                        ammoAmount -= 6;
                                        for (int i = 0; i < 7; i++)
                                            projectiles.Add(new SnowBurst(projectilePosition, Vector2.Zero, aimRotation));
                                    }
                                    break;
                                case 1:
                                    if (ammoAmount >= 16)
                                    {
                                        ammoAmount -= 16;
                                        projectiles.Add(new Grenade(projectilePosition, Vector2.Zero, aimRotation, true));
                                    }
                                    break;
                                case 2:
                                    if (ammoAmount >= 12)
                                    {
                                        ammoAmount -= 12;
                                        for (int i = 0; i < 3; i++)
                                            projectiles.Add(new IceSpear(new Vector2(position.X + 100 + (i * Game1.random.Next(10, 30)), 0 - Game1.random.Next(0, 300))));
                                    }
                                    break;
                                case 3:
                                    if (ammoAmount >= 8)
                                    {
                                        ammoAmount -= 8;
                                        projectiles.Add(new IceStar(projectilePosition, Vector2.Zero, aimRotation));
                                    }
                                    break;
                            }
                        }
                        else if (direction == -1)
                        {
                            switch (weaponToggle)
                            {
                                case 0:
                                    if (ammoAmount >= 6)
                                    {
                                        ammoAmount -= 6;
                                        for (int i = 0; i < 7; i++)
                                            projectiles.Add(new SnowBurst(projectilePosition, Vector2.Zero, aimRotation + (float)Math.PI));
                                    }
                                    break;
                                case 1:
                                    if (ammoAmount >= 16)
                                    {
                                        ammoAmount -= 16;
                                        projectiles.Add(new Grenade(projectilePosition, Vector2.Zero, aimRotation + (float)Math.PI, true));
                                    }
                                    break;
                                case 2:
                                    if (ammoAmount >= 12)
                                    {
                                        ammoAmount -= 12;
                                        for (int i = 0; i < 3; i++)
                                            projectiles.Add(new IceSpear(new Vector2(position.X - 100 - (i * Game1.random.Next(10, 30)), 0 - Game1.random.Next(0, 300))));
                                    }
                                    break;
                                case 3:
                                    if (ammoAmount >= 8)
                                    {
                                        ammoAmount -= 8;
                                        projectiles.Add(new IceStar(projectilePosition, Vector2.Zero, aimRotation + (float)Math.PI));
                                    }
                                    break;
                                    
                            }
                        }
                        RT_Pressed = false; //Resetting the values
                        RT_Held = false;
                        TotalTime = 0.0f;
                    }
                }



                //CROUCHING, ETC CONTROLS ------------------------
                if (GamePad.GetState(controllerIndex).ThumbSticks.Left.Y < 0
                    && !jumping)
                {
                    // If the ammo is full, stop the crouch animation
                    if (ammoAmount >= MAX_AMMO_AMOUNT)
                    {
                        changeFrameStartAndEnd(idleStart, idleEnd);
                        isCrouching = false;
                    }
                    else
                    {
                        // If not crouching already, then start crouching.
                        if (previousState.ThumbSticks.Left.Y >= 0)
                        {
                            changeFrameStartAndEnd(crouchStart, crouchEnd);
                            isCrouching = true;
                        }
                        // If the crouching animation is over, play the looping crouch
                        if (CurrentFrame == new Vector2(crouchEnd.X - 1, crouchEnd.Y))
                        {
                            changeFrameStartAndEnd(crouchLoopStart, crouchEnd);
                        }
                    }
                }
                // If the player is not holding down the crouch button, and they were crouching
                // then stop crouching and show the idle animation.
                else if (isCrouching)
                {
                    changeFrameStartAndEnd(idleStart, idleEnd);
                    isCrouching = false;
                }

                // If the player is crouching, they can't move or shoot.
                if (isCrouching)
                {
                    canShoot = false;
                    canMove = false;
                    if (ammoAmount < MAX_AMMO_AMOUNT)
                    {
                        ammoAmount += 0.5f;
                    }
                }
                else
                {
                    canShoot = true;
                    canMove = true;
                }

                //JUMPING CONTROLS -------------------------------
                //when A is pressed it sets accel to have gravity and sets the velocity based on direction and angle
                //you can change the jump power at the top
                //there is a right, left and idle jump
                if (GamePad.GetState(controllerIndex).Buttons.A == ButtonState.Pressed
                    && !isCrouching && !jumping)
                {
                    float timeInterval = (float)gameTime.ElapsedGameTime.Milliseconds / 1000;
                    jumping = true;
                    //playOnce(jumpStart, jumpEnd);     // CURRENTLY NOT NEEDED
                    canMove = false;
                    Acceleration = new Vector2(0f, 20f);
                    originalVelocity.X = jumpPower;
                    if (isIdle)
                    {
                        originalVelocity.X = 0f;
                        originalVelocity.Y = (float)(jumpPower * Math.Sin(Math.PI * 60 / 180.0));
                        Game1.soundJump.Play();
                    }
                    else if (direction == -1)
                    {
                        originalVelocity.Y = (float)(originalVelocity.X * Math.Sin(Math.PI * 60 / 180.0));
                        originalVelocity.X *= (float)Math.Cos(Math.PI * 60 / 180.0);
                        Game1.soundJump.Play();
                    }
                    else if (direction == 1)
                    {
                        originalVelocity.Y = (float)(originalVelocity.X * Math.Sin(Math.PI * 120 / 180.0));
                        originalVelocity.X *= (float)Math.Cos(Math.PI * 120 / 180.0);
                        Game1.soundJump.Play();
                    }
                }
                // Can be used all throughout to make sure button presses are precise
                previousState = GamePad.GetState(controllerIndex);
        }
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            Color color;
            switch (playerNumber)
            {
                case 0:
                    color = Color.White;
                    break;
                case 1:
                    color = Color.White;
                    break;
                case 2:
                    color = Color.White;
                    break;
                case 3:
                    color = Color.White;
                    break;
                default:
                    color = Color.White;
                    break;
            }
 	        base.Draw(gameTime, spriteBatch, color);
            //drawing projectiles, if they are present
            //---------------------------------------
            if (projectiles.Count > 0)
            {
                for (int i = 0; i < projectiles.Count; i++)
                {
                    projectiles[i].Draw(gameTime,spriteBatch);
                }
            }
            spriteBatch.Draw(aimImage, aimPosition, null, Color.White, aimRotation, aimOrigin, 1f, SpriteEffect, 1f);
        }
        //new Right, Left, and Idle methods for players
        public void Right(GameTime gameTime)
        {
            acceleration.X = 100f;
            float timeInterval = 0f;
            timeInterval += (float)gameTime.ElapsedGameTime.TotalSeconds;
            Velocity = OriginalVelocity + Acceleration * timeInterval;
            Position += OriginalVelocity * timeInterval + 0.5f * Acceleration * (timeInterval * timeInterval);
            OriginalVelocity = Velocity;
        }
        public void Left(GameTime gameTime)
        {
            acceleration.X = -100f;
            float timeInterval = 0f;
            timeInterval += (float)gameTime.ElapsedGameTime.TotalSeconds;
            Velocity = OriginalVelocity + Acceleration * timeInterval;
            Position += OriginalVelocity * timeInterval + 0.5f * Acceleration * (timeInterval * timeInterval);
            OriginalVelocity = Velocity;
        }
        public override void Idle()
        {
            //fixed the sliding when idle or changing direction
            acceleration.X = 0f;
            originalVelocity.X = 0;
            velocity.X = 0;
            //originalVelocity.X *= .25f;
            //velocity.X *= .25f;
        }

        public void Collision(Rectangle tileRectangle, int xOffset, int yOffset)
        {


            if (CollisionRectangle.TouchTopOf(tileRectangle))
            {
                position.Y -= 1;
                velocity.Y = -1.0f;
                jumping = false;
            }
            if (CollisionRectangle.TouchLeftOf(tileRectangle))
            {
                position.X -= 1;
                velocity.X = -1.0f;
            }  
            if (CollisionRectangle.TouchRightOf(tileRectangle))
            {
                position.X += 1;
                velocity.X = 1.0f;
            }  
            if (CollisionRectangle.TouchBottomOf(tileRectangle))
            {
                position.Y += 1;
                velocity.Y = 1.0f;
            }

            if (position.X < 0)
                position.X = 0;
            if (position.X > xOffset - CollisionRectangle.Width)
                position.X = xOffset - CollisionRectangle.Width;
            if (position.Y < 0)
                velocity.Y = 1.0f;
            if (position.Y > yOffset - CollisionRectangle.Height)
                position.Y = yOffset - CollisionRectangle.Height;
        }

        public void CheckHits(List<Player> players)
        {
            for (int i = players.Count - 1; i >= 0; i--)
            {
                if (players[i] != this)
                {
                    for (int n = players[i].projectiles.Count - 1; n >= 0; n--)
                    {
                        if (CollisionRectangle.Intersects(players[i].projectiles[n].CollisionRectangle))
                        { //HIT OCCURED:
                            Game1.soundHit3.Play();
                            //Vector2 NormalizedVector = Vector2.Normalize(players[i].projectiles[n].Velocity);
                            //position += NormalizedVector * (knockBackValue * players[i].projectiles[n].damage); << was knockback, has bugs
                            Health -= players[i].projectiles[n].damage;
                            players[i].projectiles.RemoveAt(n);
                        }
                    }
                }
            }
        }

        public void Respawn(GraphicsDevice graphicsDevice)
        {
            Game1.soundExplosion2.Play();
            Position = new Vector2(graphicsDevice.Viewport.Width / 2, TextureImage.Height);
            Health = MaxHealth;
        }
    }
}